import { Injectable } from '@nestjs/common';
import { RedisService } from '@liaoliaots/nestjs-redis';

@Injectable()
export class CommonRedisService {
  private client: any;

  constructor(private readonly redisService: RedisService) {
    this.client = this.redisService.getClient();
  }
  async get(k: string): Promise<any> {
    return await this.client.get(k);
  }
  async set(k: string, v: any, second?: number) :Promise<any> {
    if (typeof v === 'object') {
      v = JSON.stringify(v);
    }
    if (second) {
      return await this.client.set(k, v, 'EX', second)
    }
    return await this.client.set(k, v)
  }

  async del(k: string) :Promise<any> {
    return await this.client.del(k)
  }
}
